Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Graphics /
Chapter 3 - Geometric Styles / Using Geometric Styles


Constraining Shape Geometries to Grids

The source-grid style attribute (gxSourceGridStyle) allows you to specify that QuickDraw GX should constrain the coordinates of a shape's geometry to integer positions before applying the shape's style and transform. Setting this style attribute does not actually change the information stored in the shape's geometry--instead, QuickDraw GX reinterprets the shape's geometry when drawing the shape.

If a shape has no style or transform modifications, setting this style attribute has the effect of snapping the shape to a 1/72-inch grid--an effect that is visible only on high-resolution devices. However, if the shape has style or transform modifications, setting this style attribute might have visible effects even on lower-resolution devices.

For example, you can use the source-grid style attribute in combination with a scaling transform to achieve the effect of constraining a shape to a grid much larger than 1/72 inch. The sample function in Listing 3-3 shows how to use this style attribute to constrain a shape to a half-inch grid.

Listing 3-3 Constraining a shape to a half-inch grid

void ConstrainShapeToGrid(void)
{  
   gxMapping scaleToHalfInches;
   static long veeGeometry[] = {1, /* number of contours */
                                3, /* number of points */
                                fl(1.2), fl(1.1),
                                fl(2.9), fl(2.8),
                                fl(5.2), fl(.9)};
   gxShape aVeeShape;

   aVeeShape = GXNewPolygons((gxPolygons *) veeGeometry);
   GXSetShapeFill(aVeeShape, gxOpenFrameFill);
   GXSetShapePen(aVeeShape, fl(5.0 * (1.0/36.0)));

   GXResetMapping(scaleToHalfInches);
   GXScaleMapping(scaleToHalfInches, ff(36), ff(36), 
                  ff(0), ff(0));
   GXSetShapeMapping(aVeeShape, scaleToHalfInches);

   GXDrawShape(aVeeShape);

   GXDisposeShape(aVeeShape);
}
This sample function defines a small, irregular, V-shape geometry and scales the shape up by 36 points, or half an inch. The pen width is set to 5.0 (divided by 36.0 to counteract the scaling). The result of this sample function is shown in Figure 3-35.

Figure 3-35 Scaled, but not constrained, V shape

Notice that before QuickDraw GX applies the mapping, the coordinates of the shape's geometry represent points, whereas after QuickDraw GX applies the mapping, the coordinates of the shape's geometry effectively represent half inches.

If you set the source-grid style attribute by adding this line of code to the sample function:

GXSetShapeStyleAttributes(aVeeShape, gxSourceGridStyle);
QuickDraw GX constrains the coordinates of the shape's geometry to the nearest integer position before applying the mapping. Therefore, after the mapping, the shape's geometric points lie on a half-inch grid, as shown in Figure 3-36.

Figure 3-36 Constrained V shape

The sample function in this section uses some concepts from other parts of QuickDraw GX. For more information about scaling, mappings, and transforms, see the chapter "Transform Objects" in Inside Macintosh: QuickDraw GX Objects.

For more information about the gxSourceGridStyle style attribute, see "Style Attributes" on page 3-98.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help